#include <stdio.h>

#include "useless.h"

#define SIZE_TAB 4

void check_length(FILE *file)
{
  fseek(file, SEEK_SET, 0);
}

int my_strlen(const char str[])
{
	int nbchar = 0;
	int i = 0;
	char actualchar = 0;

	do
	{
		actualchar = str[i];
		i++;
		if (actualchar == '\t')
			nbchar += SIZE_TAB;
		else
			nbchar++;
	} while (actualchar != '\0');

	return (nbchar-1); /*Pour oublier le \O, mais ca compte quand même le \n*/
}

void check_len(char str[], int line)
{
	int size = 0;

	/*printf("%s", str);*/
	size = my_strlen(str);
	/*printf("%d\n", size);*/
	if (size >= 81)
		printf("Warning line %d, string is %d character\n%s", line, size, str);
}

void check(char *filename)
{
	char buffer[200] = "";
  FILE *file = NULL;
	int actualLine = 0;

  file = fopen(filename, "r");
  printf("file : %s\n", filename);
	if (file != NULL)
	{
		while (fgets(buffer, 200, file) != NULL)
		{
			actualLine++,
			check_len(buffer, actualLine);
		}
 		fclose(file);
	}
	else
	{
		printf("Erreur d'ouverture du fichier %s\n", filename);
	}
}

int main(int argc, char *argv[])
{
  int i;
  pony();
  splash();
  for(i = 1; i < argc; i++)
    check(argv[i]);
  return 0;
}
